/**  \file Page5.qml
\brief Page5 form management

Price My House for Nokia mobile platforms.

\author © 2011 Enrico Miglino / Tech Consulting (enrico.miglino@ovi.com)
\author "Evimin Fiyati Price My House" is protected by the copyright law
\author Distributed under the LGPL 3.0 license.
\date 2011

\par Licensing notes

    "Price My House" is free software: you can redistribute it
    and/or modify it under the terms of the Lesser GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Price My House" is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with "Price My House".
    If not, see <http://www.gnu.org/licenses/>.

*/

import QtQuick 1.0
import "../Qt-Complex" as Framework
import "../Qt-Complex/Geometry.js" as Geometry

Item {
    id: page5
    width: parent.width; height: parent.height

    // Flag group title
    property string txt1Title: ""; property string txt2Title: ""; property string txt3Title: ""
    // Flag options labels
    property string opt1: ""; property string opt2: ""; property string opt3: ""
    property string opt4: ""; property string opt5: ""
    // Flag info labels
    property string inf1: ""; property string inf2: ""; property string inf3: ""
    property string inf4: ""; property string inf5: ""
    // The current option contain the option value selected by the user
    property int currentOption: 1
    // change content and visibility of some fields depending on the page state
    property int pageState: 1

    // The function update all the options of the group.
    // If the user clicked a already clicked option the action should have
    // no effect.
    function updateOptions(optionNumber) {
        // Set to true the selected option regardless of its
        // current state.
        switch(optionNumber) {
        case 1: option1.switchedOn = true; break;
        case 2: option2.switchedOn = true; break;
        case 3: option3.switchedOn = true; break;
        case 4: option4.switchedOn = true; break;
        case 5: option5.switchedOn = true; break;
        }

        // User changed from false to true: switch to off previous option
        if (currentOption != optionNumber) {
            switchCurrentOption(false);
            currentOption = optionNumber;
        }
    }

    function switchCurrentOption(status) {
        switch(currentOption) {
        case 1: option1.switchedOn = status; break;
        case 2: option2.switchedOn = status; break;
        case 3: option3.switchedOn = status; break;
        case 4: option4.switchedOn = status; break;
        case 5: option5.switchedOn = status; break;
        }
    }

    // Pagetitle. The content text depends by the pageState
    Text {
        id: pagetitle
        anchors.top: parent.top; anchors.topMargin: Geometry.getSeparator() * 2
        color: "#363636"; font.pointSize: Geometry.getFontPoints() + 1;
        text: (pageState == 1) ? txt1Title : txt2Title;
        font.bold: true
    }
    Framework.GroupSwitch {
        id: swgroupPage2

        anchors.top: pagetitle.bottom; anchors.topMargin: Geometry.getFieldSpacing();
        fieldSpacing: Geometry.getFieldSpacing();
        fontPoints: Geometry.getFontPoints();
        fieldSeparator: Geometry.getFieldSpacing();
        switchHeigth: Geometry.getFieldHeight();
        fontSwitches: Geometry.getFontPoints() - 2;

        themeString: "PMH"
        grouptitle: txt3Title
        sw1_field: opt1; sw1_info: inf1; sw1_infoshow: true; sw1_state: true; sw1_obj: (page5.pageState == 1) ? "Switch" : ""
        sw2_field: opt2; sw2_info: inf2; sw2_infoshow: true; sw2_state: false; sw2_obj: "Switch"
        sw3_field: opt3; sw3_info: inf3; sw3_infoshow: true; sw3_state: false; sw3_obj: "Switch"
        sw4_field: opt4; sw4_info: inf4; sw4_infoshow: true; sw4_state: false; sw4_obj: "Switch"
        sw5_field: opt5; sw5_info: inf5; sw5_infoshow: true; sw5_state: true; sw5_obj: (page5.pageState == 2) ? "Switch" : ""
    }
}
